package com.peng.controller;

import com.github.pagehelper.PageInfo;
import com.peng.Repo.PageStatic;
import com.peng.pojo.User;
import com.peng.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @GetMapping("/teacherList")
    public PageInfo<User> getTeacher(@RequestParam(name = "username", defaultValue = "") String username,
                                     @RequestParam(name = "page", defaultValue = PageStatic.page) Integer page,
                                     @RequestParam(name = "size", defaultValue = PageStatic.size) Integer size) {
        return teacherService.selectTeacherAll(username, page, size);
    }

    @PostMapping("/addTeacher")
    public String addTeacher(User user) {
        if (user != null) {
            if (teacherService.addTeacher(user)) {
                return "true";
            }
        }
        return "false";
    }
    @GetMapping("/updateTeacherStauts")
    public String updateTeacherStatus(int status, Integer... id) {
        teacherService.updateTeacherStatus(status, id);
        return "true";
    }
    @GetMapping("/deleteTeacher")
    public String deleteTeacher(Integer... id) {
        teacherService.deleteTeacherById(id);
        return "true";
    }
}
